# coding:utf-8
import time, random, hashlib, sys

__version__ = "0.1"
__author__ = 'ChengHao'
__license__ = 'MIT'
__mail__ = 'hao2432@gmail.com'
__url__ = 'https://github.com/chenghao'

PY3 = (sys.version_info[0] == 3)  # Python3
PY2 = (sys.version_info[0] == 2)  # Python2


def get_out_trade_no():
    """
    获取商户订单号 （当前毫秒数 + 4位随机数）
    :return:  订单号
    """
    t = time.time()
    millisecond = int(round(t * 1000))          # 获取当前毫秒数
    random_int = random.randint(0000, 9999)     # 获取4位随机数
    return str(millisecond) + str(random_int)


def md5_encode(s):
    """
    MD5加密
    :param s:  加密前的数据
    :return:   加密后的数据 (小写)
    """
    m = hashlib.md5()
    if PY3:
        m.update(s.encode("latin1"))
    else:
        m.update(s)
    return m.hexdigest()


if __name__ == "__main__":
    print(get_out_trade_no())
    print(md5_encode("123456"))
